package com.xiaojian.pick.controller;

import com.xiaojian.pick.entity.TopicSupport;
import com.xiaojian.pick.page.AjaxResult;
import com.xiaojian.pick.service.TopicSupportService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author whycode
 * @title: CommentSupportController
 * @projectName campus-secondary-market-app---sys
 * @description: TODO
 * @date 2022/4/916:21
 */

@RestController
@RequestMapping("/commentSupport")
public class TopicSupportController {

    @Resource
    private TopicSupportService service;

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestBody TopicSupport topicSupport){
        service.save(topicSupport);
        List<TopicSupport> supports = service.queryByTopic(topicSupport.getTopicId());
        return new AjaxResult(true).setData(supports);
    }

    @DeleteMapping("/delete")
    @ResponseBody
    public AjaxResult delete(@RequestBody TopicSupport topicSupport){
        service.delete(topicSupport);
        List<TopicSupport> supports = service.queryByTopic(topicSupport.getTopicId());
        return new AjaxResult(true).setData(supports);
    }

    @GetMapping("/all/{topicId}")
    @ResponseBody
    public AjaxResult query(@PathVariable("topicId") Integer topicId){
        List<TopicSupport> list = service.queryByTopic(topicId);
        return new AjaxResult(true).setData(list);
    }
}
